<template>
  <div v-loading="infoLoading">
    <el-dialog
      :title="dialogTitle1"
      :visible.sync="dialogVisible1"
      width="98%"
      top="20px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
    >
      <el-form ref="postForm1" :model="postForm1" class="form-container" label-width="200px" :rules="rules1">
        <el-form-item key="lx" label="类型" prop="lx">
          <el-select v-model="postForm1.lx" placeholder="请选择" clearable style="width: 200px" class="filter-item">
            <el-option v-for="(it,index) in lxList" :key="index" :label="it.label" :value="it.value" />
          </el-select>
        </el-form-item>
        <div />
        <el-form-item v-if="postForm1.lx==='0201'" key="zb" prop="zb" label="占比">
          <el-input-number v-model="postForm1.zb" style="width:200px" /> %
        </el-form-item>
        <el-form-item v-if="postForm1.lx==='0202'" key="pp" prop="pp" label="品牌">
          <el-input v-model="postForm1.pp" style="width:200px" />
        </el-form-item>
        <el-form-item v-if="postForm1.lx==='0202'" key="cph" prop="cph" label="车牌号">
          <el-input v-model="postForm1.cph" style="width:200px" />
        </el-form-item>
        <el-form-item v-if="postForm1.lx==='0203'||postForm1.lx==='0204'" key="dz" prop="dz" label="地址">
          <el-input v-model="postForm1.dz" style="width:400px" />
        </el-form-item>
        <el-form-item v-if="postForm1.lx==='0203'||postForm1.lx==='0204'" key="mj" prop="mj" label="面积">
          <el-input-number v-model="postForm1.mj" style="width:200px" /> 平米
        </el-form-item>
        <el-form-item v-if="postForm1.lx==='0205'||postForm1.lx==='0206'||postForm1.lx==='0207'" key="xq" prop="xq" label="详情">
          <el-input v-model="postForm1.xq" style="width:400px" />
        </el-form-item>
        <div />
        <el-form-item key="zt" label="状态" prop="zt">
          <el-select v-model="postForm1.zt" placeholder="请选择" clearable style="width: 200px" class="filter-item">
            <el-option label="无" :value="null" />
            <el-option v-for="(it,index) in ztList" :key="index" :label="it.label" :value="it.value" />
          </el-select>
        </el-form-item>
        <el-form-item key="sm" label="说明备注" prop="sm">
          <el-input v-model="postForm1.sm" type="textarea" style="width:400px" />
        </el-form-item>
        <div />
        <el-form-item key="submit" style="margin:10px 0 0 200px">
          <el-button type="primary" :loading="loading" @click="submitForm1">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :title="dialogTitle2"
      :visible.sync="dialogVisible2"
      width="98%"
      top="20px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
    >
      <el-form ref="postForm2" :model="postForm2" class="form-container" label-width="200px" :rules="rules2">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="postForm2.name" style="width:200px" />
        </el-form-item>
        <!-- <el-form-item label="年龄" prop="age">
          <el-input-number v-model="postForm2.age" style="width:200px" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="postForm2.sex">
            <el-radio label="男" />
            <el-radio label="女" />
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="身份证号" prop="idcard">
          <el-input v-model="postForm2.idcard" style="width:200px" />
        </el-form-item>
        <el-form-item label="家庭住址" prop="address">
          <el-input v-model="postForm2.address" style="width:600px" />
        </el-form-item>
        <el-form-item label="户籍所在地" prop="hjszd">
          <el-input v-model="postForm2.hjszd" style="width:600px" />
        </el-form-item>
        <el-form-item label="强制措施日期" prop="qzdate">
          <el-date-picker v-model="postForm2.qzdate" type="date" value-format="yyyy-MM-dd" placeholder="请选择" style="width:200px" />
        </el-form-item>
        <el-form-item label="强制措施种类" prop="qztype">
          <el-select v-model="postForm2.qztype" placeholder="请选择" clearable style="width: 200px" class="filter-item">
            <el-option label="无" :value="null" />
            <el-option v-for="(it,index) in qztypeList" :key="index" :label="it.label" :value="it.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading" @click="submitForm2">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :title="fileDialogTitle"
      :visible.sync="fileDialogVisible"
      width="98%"
      top="20px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
    >
      <el-form ref="filePostForm" :model="filePostForm" class="form-container" label-width="200px">
        <el-form-item v-if="!readOnly" label="文件" prop="file">
          <el-upload
            class="upload-demo"
            :action="this.$http.defaults.baseURL+'api/gen/file/upload/'"
            :on-success="handleUploadSucc"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :on-error="uploadError"
            :multiple="false"
            :file-list="fileList"
            :headers="myHeaders"
            :limit="1"
            :on-exceed="handleExceed"
          >
            <el-button type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="说明" prop="address">
          <el-input v-model="filePostForm.remark" type="textarea" style="width:800px" rows="10" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading" @click="submitFileForm">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <h2>立案侦查</h2>
    <el-alert
      v-if="postForm.gazt===3"
      title="审核未通过"
      type="error"
      :description="'原因：'+hist.auditResult?hist.auditResult:'读取中...'"
      show-icon
    />
    <el-form ref="postForm" :model="postForm" :rules="rules" class="form-container" label-width="200px" :inline="true">
      <!-- <el-form-item label="处非案件编号" prop="cfajbh" style="width:500px;">
        {{ postForm.id?postForm.cfajbh:'自动生成' }}
      </el-form-item> -->
      <table cellspacing="0" cellpadding="0" border="0" class="formTable" style="margin-bottom:10px;">
        <tr>
          <th>案件名称</th>
          <td colspan="3">
            <el-form-item label="" prop="ajmc">
              <el-input v-if="!readOnly" v-model="postForm.ajmc" style="width:300px" />
              <span v-else>{{ postForm.ajmc }}</span>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <th v-html="'<p>案&#8194;件&#8194;号</p>'" />
          <td>
            <el-form-item label="" prop="ajh">
              <el-input v-if="!readOnly" v-model="postForm.ajh" style="width:200px" />
              <span v-else>{{ postForm.ajh }}</span>
            </el-form-item>
          </td>
          <th>涉及范围</th>
          <td>
            <el-form-item label="" prop="sjfw">
              <el-select v-if="!readOnly" v-model="postForm.sjfw" placeholder="请选择" clearable style="width: 200px" class="filter-item">
                <el-option value="廊坊" />
                <el-option value="省内" />
                <el-option value="全国" />
              </el-select>
              <span v-else>{{ postForm.sjfw }}</span>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <th v-html="'<p>法&#12288;&#12288;人</p>'" />
          <td>
            <el-form-item label="" prop="fr">
              <el-input v-if="!readOnly" v-model="postForm.fr" style="width:200px" />
              <span v-else>{{ postForm.fr }}</span>
            </el-form-item>
          </td>
          <th>实际控制人</th>
          <td>
            <el-form-item label="" prop="sjkzr">
              <el-input v-if="!readOnly" v-model="postForm.sjkzr" style="width:200px" />
              <span v-else>{{ postForm.sjkzr }}</span>
            </el-form-item>
          </td>
        </tr><tr>
          <th>涉及金额<br>（万元）</th>
          <td>
            <el-form-item label="" prop="sjje">
              <el-input-number v-if="!readOnly" v-model="postForm.sjje" />
              <span v-else>{{ postForm.sjje }}</span>
            </el-form-item>
          </td>
          <th>未兑付金额<br>（万元）</th>
          <td>
            <el-form-item label="" prop="wdfje">
              <el-input-number v-if="!readOnly" v-model="postForm.wdfje" />
              <span v-else>{{ postForm.wdfje }}</span>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <th>集资人数</th>
          <td>
            <el-form-item label="" prop="jzrs">
              <el-input-number v-if="!readOnly" v-model="postForm.jzrs" />
              <span v-else>{{ postForm.jzrs }}</span>
            </el-form-item>
          </td>
          <th>立案时间</th>
          <td>
            <el-form-item label="" prop="lasj">
              <el-date-picker v-if="!readOnly" v-model="postForm.lasj" style="width:200px" value-format="yyyy-MM-dd" />
              <span v-else>{{ postForm.lasj }}</span>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <th>办案单位</th>
          <td>
            <el-form-item label="" prop="badw">
              <el-input v-if="!readOnly" v-model="postForm.badw" style="width:300px" />
              <span v-else>{{ postForm.badw }}</span>
            </el-form-item>
          </td>
          <th>办案负责人</th>
          <td>
            <el-form-item label="" prop="bafzr">
              <el-input v-if="!readOnly" v-model="postForm.bafzr" style="width:200px" />
              <span v-else>{{ postForm.bafzr }}</span>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <th>案件简述</th>
          <td colspan="3">
            <el-form-item label="" prop="ajjs">
              <el-input v-if="!readOnly" v-model="postForm.ajjs" type="textarea" style="width:710px" />
              <span v-else v-html="postForm.ajjs" />
            </el-form-item>
          </td>
        </tr>
      </table>
      <el-switch
        v-model="showmore"
        active-color="#13ce66"
        inactive-color="#ff4949"
        style="margin:0 10px 0 20px;"
      />{{ showmore?'隐藏更多':'显示更多' }}
      <div v-show="showmore">
        <h3>查扣资产情况</h3>
        <el-button v-if="!readOnly" type="primary" style="float:left;margin:0 10px 10px 0" @click="getXls(0)">下载模板</el-button>
        <el-upload
          v-if="!readOnly"
          :action="this.$http.defaults.baseURL+'api/ga/importKczcqk/'"
          :on-success="importckzcqk"
          :headers="myHeaders"
          :show-file-list="false"
          style="float:left"
        >
          <el-button type="success">导入</el-button>
        </el-upload>
        <el-table
          ref="processTable"
          :data="zcqkList"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:20px;"
        >
          <el-table-column key="lx" align="center" prop="lx" label="类型" width="100">
            <template slot-scope="scope">
              {{ lxText(scope.row.lx) }}
            </template>
          </el-table-column>
          <el-table-column key="xq" prop="xq" label="详情" min-width="250" align="left">
            <template slot-scope="scope">
              {{ xqText(scope.row) }}
            </template>
          </el-table-column>
          <el-table-column key="zt" align="center" prop="zt" label="状态" width="100">
            <template slot-scope="scope">
              {{ ztText(scope.row.zt) }}
            </template>
          </el-table-column>
          <el-table-column key="sm" align="center" prop="sm" label="说明备注" width="200" />
          <el-table-column v-if="!readOnly" key="cz" width="200">
            <template slot="header">
              <el-button
                type="success"
                @click="add1"
              >新增</el-button>
            </template>
            <template slot-scope="scope">
              <el-button
                type="primary"
                @click="handleEdit(scope.$index, scope.row)"
              >修改</el-button>
              <el-popconfirm title="确定删除该信息吗？" style="margin-left:10px;" @onConfirm="handleDelete(scope.$index)">
                <el-button slot="reference" type="danger">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <h3>嫌疑人羁押、管控情况</h3>
        <el-button v-if="!readOnly" type="primary" style="float:left;margin:0 10px 10px 0" @click="getXls(1)">下载模板</el-button>
        <el-upload
          v-if="!readOnly"
          :action="this.$http.defaults.baseURL+'api/ga/importXyrgkqk/'"
          :on-success="importxyr"
          :headers="myHeaders"
          :show-file-list="false"
          style="float:left"
        >
          <el-button type="success">导入</el-button>
        </el-upload>
        <el-table
          ref="processTable"
          :data="gkqkList"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:20px;margin-top:10px;"
        >
          <el-table-column key="xm" prop="xm" label="姓名" width="70" align="center" />
          <!-- <el-table-column prop="nl" label="年龄" width="60" align="center" />
          <el-table-column prop="xb" label="性别" width="60" align="center" /> -->
          <el-table-column key="sfzh" prop="sfzh" label="身份证号" width="180" align="center" />
          <el-table-column key="jtzz" prop="jtzz" label="家庭住址" min-width="250" align="center" />
          <el-table-column key="hjszd" prop="hjszd" label="户籍所在地" width="320" align="center" />
          <el-table-column key="qzcsrq" prop="qzcsrq" label="强制措施日期" width="120" align="center" />
          <el-table-column key="qzcszl" prop="qzcszl" label="强制措施种类" width="150" align="center">
            <template slot-scope="scope">
              {{ qztypeText(scope.row.qzcszl) }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="!readOnly"
            key="cz"
            width="200"
          >
            <template slot="header">
              <el-button
                type="success"
                @click="add2"
              >新增</el-button>
            </template>
            <template slot-scope="scope">
              <el-button
                type="primary"
                @click="handleEdit2(scope.$index, scope.row)"
              >修改</el-button>
              <el-popconfirm title="确定删除该信息吗？" style="margin-left:10px;" @onConfirm="handleDelete2(scope.$index)">
                <el-button slot="reference" type="danger">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>

        <!-- <h3>附件</h3>
        <el-table
          ref="processTable"
          :data="fjList"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:20px;"
          :loading="fjloading"
        >
          <el-table-column prop="name" label="文件名" width="400" align="left" show-overflow-tooltip />
          <el-table-column prop="dataCreateDatetime" label="上传时间" width="160" align="center" />
          <el-table-column prop="remark" label="说明" min-width="400" align="left" show-overflow-tooltip />
          <el-table-column width="300">
            <template slot="header">
              <el-button
                type="success"
                @click="addFile"
              >新增</el-button>
            </template>
            <template slot-scope="scope">
              <el-button
                @click="download(scope.row)"
              >下载</el-button>
              <el-button
                type="primary"
                @click="editFile(scope.$index,scope.row)"
              >修改</el-button>
              <el-popconfirm title="确定删除该信息吗？" style="margin-left:10px;" @onConfirm="handleDeleteFile(scope.$index)">
                <el-button slot="reference" type="danger">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table> -->
      </div>
      <div />
      <el-form-item style="margin:10px 0">
        <el-button v-if="!readOnly" type="warning" :loading="loading" @click="submitForm(0)">办理中</el-button>
        <el-button v-if="!readOnly" type="success" :loading="loading" @click="submitForm(1)">已完成</el-button>
      </el-form-item>
    </el-form>
    <el-form v-if="auditFlag" ref="auditForm" :model="auditForm" class="form-container" label-width="200px">
      <el-form-item label="是否通过" prop="auditState">
        <el-radio-group v-model="auditForm.auditState">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">未通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="auditFlag&&!auditForm.auditState" label="未通过原因" prop="auditResult">
        <el-input v-model="auditForm.auditResult" style="width:810px" />
      </el-form-item>
      <el-form-item style="margin:10px 0">
        <el-button type="success" :loading="loading" @click="submitAudit">审核</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
const defaultForm = {
  ajh: '',
  ajmc: '',
  ajfw: '',
  sjfw: '',
  fr: '',
  sjkzr: '',
  sjje: '',
  wdfje: '',
  jzrs: '',
  lasj: '',
  badw: '',
  bafzr: '',
  ajjs: '',
  id: null
}
const defaultForm1 = {
  lx: '',
  zb: 0,
  dz: '',
  mj: 0,
  pp: '',
  cph: '',
  xq: '',
  zt: '',
  sm: ''
}
const defaultForm2 = {
  name: '',
  age: '',
  // sex: '',
  idcard: '',
  address: '',
  hjszd: '',
  qzdate: '',
  qztype: ''
}
const defaultFileForm = {
  fileid: 0,
  remark: ''
}
const defaultAuditForm = {
  auditResult: '',
  auditState: 1
}
export default {
  name: 'ArticleDetail',
  props: {
    readOnly: {
      type: Boolean,
      default: false
    },
    showDuban: {
      type: Boolean,
      default: false
    },
    infoid: {
      type: Number,
      default: 0
    },
    timestamp: {
      type: Number,
      default: 0
    },
    step: {
      type: String,
      default: ''
    }
  },
  data() {
    const validateRequire = (rule, value, callback) => {
      if (value === null || value === undefined || value === '') {
        // this.$message({
        //   message: '请将表单填写完整',
        //   type: 'error'
        // })
        callback(new Error('必填项'))
      } else {
        callback()
      }
    }
    return {
      hist: {},
      auditFlag: false,
      fjloading: false,
      fjindex: -1,
      fileList: [],
      showmore: false,
      xyrindex: -1,
      zcindex: -1,
      ztList: [],
      lxList: [],
      zlList: [],
      fjlList: [],
      fjList: [],
      qztypeList: [],
      dialogVisible1: false,
      dialogTitle1: '新增',
      dialogVisible2: false,
      dialogTitle2: '新增',
      fileDialogVisible: false,
      fileDialogTitle: '新增',
      zcqkList: [
        // { type: '股权', content: '占比：50%' },
        // { type: '车辆', content: '品牌：奔驰S300 车牌号：冀RXXXXX', state: '查封手续', remarks: '' },
        // { type: '房产', content: '广阳区某某小区1-1-101 面积：130.11平米', state: '查封', remarks: '' },
        // { type: '土地', content: '广阳区某某乡某某村 面积：10000平米', state: '未查封', remarks: '' },
        // { type: '贵金属', content: '黄金5000g', state: '', remarks: '' },
        // { type: '办公用品', content: '惠普打印机S111一台', state: '', remarks: '' }
      ],
      gkqkList: [
        // { name: '张三', age: '40', sex: '男', idcard: '131002198001011234', address: '广阳区某某小区1-1-101', hjszd: '河北省廊坊市', qzdate: '2021-05-01', qztype: '拘留' }
      ],
      roleName: '',
      deptName: '',
      realName: '',
      myHeaders: {},
      imageUrl: '',
      infoLoading: false,
      postForm: Object.assign({}, defaultForm),
      postForm1: Object.assign({}, defaultForm1),
      postForm2: Object.assign({}, defaultForm2),
      filePostForm: Object.assign({}, defaultFileForm),
      auditForm: Object.assign({}, defaultAuditForm),
      loading: false,
      deptOption: [],
      userOption: [],
      processUserOption: [],
      priorityOption: [],
      classCodeOption: [],
      flowTypeOption: [],
      rules: {
        ajmc: [{ validator: validateRequire }]
      },
      rules1: {
        lx: [{ validator: validateRequire }],
        zb: [{ validator: validateRequire }],
        pp: [{ validator: validateRequire }],
        cph: [{ validator: validateRequire }],
        mj: [{ validator: validateRequire }],
        dz: [{ validator: validateRequire }],
        xq: [{ validator: validateRequire }]
      },
      rules2: {
        name: [{ validator: validateRequire }]
        // sex: [{ validator: validateRequire }],
        // age: [{ validator: validateRequire }],
        // idcard: [{ validator: validateRequire }],
        // address: [{ validator: validateRequire }],
        // hjszd: [{ validator: validateRequire }]
      },
      tempRoute: {},
      processListLoading: false,
      processList: [
        // { time: '第一次', unit1: '处非办', unit2: '公安局', date: '2021-05-10', limit: '10天', item: '尽快办理', result: '已办结' },
        // { time: '第二次', unit1: '处非办', unit2: '公安局', date: '2021-05-20', limit: '10天', item: '尽快办理', result: '已办结' }
      ],
      processNow: {},
      mystep: ''
    }
  },
  watch: {
    timestamp: {
      handler(val, oldVal) {
        if (this.$refs['postForm']) {
          this.$refs['postForm'].resetFields()
        }
        this.mystep = this.step
        this.getData(this.infoid)
      },
      immediate: true
    }
  },
  mounted() {
    this.myHeaders = {
      Authorization: 'Bearer ' + localStorage.getItem('token')
    }
    this.getOptions()
    const day = new Date()
    day.setTime(day.getTime())
    console.log(JSON.parse(localStorage.getItem('user')))
    this.roleName = JSON.parse(localStorage.getItem('user')).roleName
    // this.postForm.publishTime = day.getFullYear() + '-' + this.add0(day.getMonth() + 1) + '-' + this.add0(day.getDate())
  },
  created() {
    this.tempRoute = Object.assign({}, this.$route)
  },
  methods: {
    showSupervise() {
      return true
      // return JSON.parse(localStorage.getItem('user')).unitName === '处非办' || JSON.parse(localStorage.getItem('user')).unitName === '公安' || JSON.parse(localStorage.getItem('user')).unitName === '督查室' || JSON.parse(localStorage.getItem('user')).unitName === '政法委'
    },
    // 提交审核
    submitAudit() {
      // if (this.auditForm.auditState === 0 && this.auditForm.auditResult === '') {
      //   this.$message({
      //     message: '审核不通过请说明原因',
      //     type: 'error'
      //   })
      // } else {
      const para = {
        id: this.postForm.id,
        auditResult: this.auditForm.auditResult,
        auditState: this.auditForm.auditState
      }
      this.loading = true
      this.$http
        .post('/api/ga/audit', para)
        .then(response => {
          this.loading = false
          if (response.data.success === true) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.$emit('dialogHide')
            this.auditForm = Object.assign({}, defaultAuditForm)
            this.loading = false
            this.$router.back()
          } else {
            console.log('操作失败:' + response.data.message)
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.loading = false
        })
      // }
    },
    updateFj(list) {
      this.fjList = list
    },
    download(item) {
      window.open(this.$http.defaults.baseURL + 'api/gen/file/download?id=' + item.id)
    },
    getXls(id) {
      switch (id) {
        case 0:
          window.open('/ckzc.xlsx')
          break
        case 1:
          window.open('/xyr.xlsx')
          break
      }
    },
    handleExceed(files, fileList) {
      this.$message.warning(`一次最多只能上传一个文件`)
    },
    uploadError(err) {
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error',
        duration: 10000
      })
    },
    handleUploadSucc(response, file, fileList) {
      if (response.success) {
        this.$message({
          type: 'success',
          message: '上传成功!'
        })
        this.fileList.push({ id: response.result[0].id, name: response.result[0].fileName + '.' + response.result[0].fileType, url: this.$http.defaults.baseURL + 'api/gen/file/download?id=' + response.result[0].id, dataCreateDatetime: response.result[0].dataCreateDatetime })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error',
          duration: 10000
        })
      }
    },
    dateFormat(date) {
      console.log('日期转换')
      console.log(date)
      return date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
    },
    importxyr(response, file, fileList) {
      if (response.success) {
        this.gkqkList = response.result.map(it => {
          it.qzcsrq = it.qzcsrq ? this.dateFormat(new Date(it.qzcsrq)) : ''
          if (!it.qzcszl || it.qzcszl === '无') {
            it.qzcszl = null
          } else {
            it.qzcszl = this.qztypeList.find(item => item.label === it.qzcszl).value
          }
          return it
        })
      } else {
        this.$message({
          message: '导入失败:' + response.message,
          type: 'error',
          duration: 10000
        })
      }
    },
    importckzcqk(response, file, fileList) {
      if (response.success) {
        this.zcqkList = response.result.map(it => {
          it.lx = this.lxList.find(item => item.label === it.lx).value
          if (!it.zt || it.zt === '无') {
            it.zt = null
          } else {
            it.zt = this.ztList.find(item => item.label === it.zt).value
          }
          return it
        })
      } else {
        this.$message({
          message: '导入失败:' + response.message,
          type: 'error',
          duration: 10000
        })
      }
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
      const fid = file.id
      this.$http.get('api/gen/file/remove?id=' + fid).then(res => {
        if (res.data.success === true) {
          this.fileList = this.fileList.filter(item => item.id !== fid)
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
        }
      })
    },
    handleDelete(index) {
      this.zcqkList.splice(index, 1)
    },
    handleDelete2(index) {
      this.gkqkList.splice(index, 1)
    },
    handleDeleteFile(index) {
      this.fjList.splice(index, 1)
    },
    qztypeText(val) {
      if (this.qztypeList.find(item => item.value === val)) {
        return this.qztypeList.find(item => item.value === val).label
      } else {
        return ''
      }
    },
    ztText(val) {
      if (this.ztList.find(item => item.value === val)) {
        return this.ztList.find(item => item.value === val).label
      } else {
        return ''
      }
    },
    lxText(val) {
      if (this.lxList.find(item => item.value === val)) {
        return this.lxList.find(item => item.value === val).label
      } else {
        return ''
      }
    },
    xqText(row) {
      switch (row.lx) {
        case '0201':
          return '占比：' + (row.zb ? row.zb : '') + '%'
        case '0202':
          return '品牌：' + (row.pp ? row.pp : '') + '，车牌号：' + (row.cph ? row.cph : '')
        case '0203':
        case '0204':
          return '地址：' + (row.dz ? row.dz : '') + '，面积：' + (row.mj ? row.mj : '') + '平米'
        default:
          return (row.xq ? row.xq : '')
      }
    },
    submitForm1() {
      this.$refs.postForm1.validate(valid => {
        if (valid) {
          let item = {}
          switch (this.postForm1.lx) {
            case '0201':
              item = { 'lx': this.postForm1.lx, 'zb': this.postForm1.zb, 'zt': this.postForm1.zt, 'sm': this.postForm1.sm }
              break
            case '0202':
              item = { 'lx': this.postForm1.lx, 'pp': this.postForm1.pp, 'cph': this.postForm1.cph, 'zt': this.postForm1.zt, 'sm': this.postForm1.sm }
              break
            case '0203':
            case '0204':
              item = { 'lx': this.postForm1.lx, 'dz': this.postForm1.dz, 'mj': this.postForm1.mj, 'zt': this.postForm1.zt, 'sm': this.postForm1.sm }
              break
            default:
              item = { 'lx': this.postForm1.lx, 'xq': this.postForm1.xq, 'zt': this.postForm1.zt, 'sm': this.postForm1.sm }
              break
          }
          if (this.zcindex === -1) {
            this.zcqkList.push(item)
          } else {
            this.zcqkList[this.zcindex] = item
          }
          this.dialogVisible1 = false
          this.$message({
            message: '保存成功',
            type: 'success'
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitForm2() {
      this.$refs.postForm2.validate(valid => {
        if (valid) {
          const item = { 'xm': this.postForm2.name, 'sfzh': this.postForm2.idcard, 'jtzz': this.postForm2.address, 'hjszd': this.postForm2.hjszd, 'qzcsrq': this.postForm2.qzdate, 'qzcszl': this.postForm2.qztype }
          if (this.xyrindex === -1) {
            this.gkqkList.push(item)
          } else {
            console.log(item)
            console.log(this.xyrindex)
            this.gkqkList[this.xyrindex] = item
          }
          this.dialogVisible2 = false
          this.$message({
            message: '保存成功',
            type: 'success'
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitFileForm() {
      if (this.fileList && this.fileList.length > 0) {
        console.log(this.fileList)
        this.fileList[0].remark = this.filePostForm.remark
        this.filePostForm = Object.assign({}, defaultFileForm)
        if (this.fjindex === -1) {
          this.fjList.push(this.fileList[0])
        } else {
          this.fjList[this.fjindex] = this.fileList[0]
          this.fjindex = -1
        }
        this.fileList = []
        this.fileDialogVisible = false
      } else {
        this.$message({
          message: '请上传文件',
          type: 'error'
        })
      }
    },
    editFile(index, item) {
      this.fileList = []
      this.fileList.push(item)
      this.filePostForm.remark = item.remark
      this.filePostForm.dataCreateDatetime = item.dataCreateDatetime
      this.fjindex = index
      this.fileDialogVisible = true
      this.fileDialogTitle = '修改'
    },
    handleEdit(index, item) {
      this.postForm1 = item
      this.zcindex = index
      this.dialogVisible1 = true
      this.dialogTitle1 = '修改'
    },
    handleEdit2(index, item) {
      this.postForm2.name = item.xm
      // this.postForm2.age = item.nl
      // this.postForm2.sex = item.xb
      this.postForm2.idcard = item.sfzh
      this.postForm2.qzdate = item.qzcsrq
      this.postForm2.qztype = item.qzcszl
      this.postForm2.address = item.jtzz
      this.postForm2.hjszd = item.hjszd
      this.xyrindex = index
      this.dialogVisible2 = true
      this.dialogTitle2 = '修改'
    },
    add1() {
      this.zcindex = -1
      this.postForm1 = Object.assign({}, defaultForm1)
      this.dialogVisible1 = true
      this.dialogTitle1 = '新增'
    },
    add2() {
      this.xyrindex = -1
      this.postForm2 = Object.assign({}, defaultForm2)
      this.dialogVisible2 = true
      this.dialogTitle2 = '新增'
    },
    addFile() {
      this.filePostFormForm = Object.assign({}, defaultFileForm)
      this.fileDialogVisible = true
      this.fileDialogTitle = '新增'
    },
    handleAvatarSuccess(res, file) {
      // this.imageUrl = URL.createObjectURL(file.raw)
      console.log('test')
      if (res.success) {
        this.$message({
          message: '上传成功！',
          type: 'success'
        })
        this.imageUrl = res.result[0].id
        // this.fileList = []
        // this.files = []
      } else {
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    getHist() {
      const para = {
        actName: '立案侦查',
        actState: 1,
        cfajbh: this.postForm.cfajbh,
        pageNum: 1,
        pageSize: 1
        // publishTime: this.listQuery.publishTime,
        // title: this.listQuery.title
      }
      this.$http
        .post('/api/busHist/queryByPage', para)
        .then(response => {
          if (response.data.success === true) {
            this.hist = response.data.result.records[0]
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
        })
    },
    getData(id) {
      this.infoLoading = true
      if (id) {
        this.$http
          .get('/api/ga/getGaById?&id=' + id)
          .then(response => {
            this.infoLoading = false
            if (response.data.success === true) {
              this.postForm = response.data.result
              this.gkqkList = response.data.result.gkqkList
              this.zcqkList = response.data.result.zcqkList

              const userinfo = JSON.parse(localStorage.getItem('user'))
              const unitName = userinfo.unitName
              const roleName = userinfo.roleName
              if (response.data.result.gazt === 1 && unitName === '公安' && roleName === '审核') {
                this.auditFlag = true
              } else {
                this.auditFlag = false
              }
              if (response.data.result.gazt === 3) {
                this.getHist()
              }
            } else {
              console.log('获取失败:' + response.data.message)
              this.$message({
                message: '获取失败:' + response.data.message,
                type: 'error'
              })
            }
          })
          .catch(error => {
            console.log(error)
            this.infoLoading = false
          })
      } else {
        this.$nextTick(() => {
          this.infoLoading = false
          this.postForm = Object.assign({}, defaultForm)
          this.zcqkList = []
          this.gkqkList = []
          this.fjList = []
        })
      }
    },
    getFj(id) {
      const para = {
        pageNum: 1,
        pageSize: 1000,
        cfajbh: id,
        businessTable: 'bus_ga'
      }
      this.fjloading = true
      this.$http
        .post('/api/gen/file/search', para)
        .then(response => {
          this.loading = false
          if (response.data.success === true) {
            this.fjList = response.data.result.records.map(item => { return { name: item.fileName + '.' + item.fileType, remark: item.remark, id: item.id, dataCreateDatetime: item.dataCreateDatetime } })
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(function(error) {
          console.log(error)
          this.fjloading = false
        })
    },
    getOptions() {
      let code = '01'
      this.$http
        .get('/api/sysDict/getByCode?enabled=true&code=' + code)
        .then(response => {
          if (response.data.success === true) {
            this.ztList = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
        })
      code = '02'
      this.$http
        .get('/api/sysDict/getByCode?enabled=true&code=' + code)
        .then(response => {
          if (response.data.success === true) {
            this.lxList = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
        })
      code = '03'
      this.$http
        .get('/api/sysDict/getByCode?enabled=true&code=' + code)
        .then(response => {
          if (response.data.success === true) {
            this.qztypeList = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
        })
    },
    submitForm(flag) {
      this.$refs.postForm.validate(valid => {
        if (valid) {
          const para = {
            id: this.postForm.id ? this.postForm.id : null,
            ajh: this.postForm.ajh,
            ajmc: this.postForm.ajmc,
            ajfw: this.postForm.ajfw,
            sjfw: this.postForm.sjfw,
            fr: this.postForm.fr,
            sjkzr: this.postForm.sjkzr,
            sjje: this.postForm.sjje,
            wdfje: this.postForm.wdfje,
            jzrs: this.postForm.jzrs,
            lasj: this.postForm.lasj,
            badw: this.postForm.badw,
            bafzr: this.postForm.bafzr,
            ajjs: this.postForm.ajjs,
            gkqkList: this.gkqkList,
            zcqkList: this.zcqkList,
            files: this.fjList.map(item => { return { fileId: item.id, remark: item.remark, classCode: item.classCode } }),
            gazt: flag
          }
          this.loading = true
          this.$http
            .post('/api/ga/saveGa', para)
            .then(response => {
              this.loading = false
              if (response.data.success === true) {
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
                this.$emit('dialogHide')
                this.postForm = Object.assign({}, defaultForm)
                this.loading = false
                this.$router.back()
              } else {
                console.log('操作失败:' + response.data.message)
                this.$message({
                  message: '操作失败:' + response.data.message,
                  type: 'error'
                })
              }
            })
            .catch(error => {
              console.log(error)
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style>
.formTable{
  border-top:1px solid #dfe6ec;
  border-left:1px solid #dfe6ec;
  width: 100%;
}
.formTable td{
  border-bottom:1px solid #dfe6ec;
  border-right:1px solid #dfe6ec;
  margin:0;
  min-width: 500px;
  vertical-align: middle;
}
.formTable td div.el-form-item{
  font-size:14px;
  margin-top:22px;
  margin-left:20px;
}
.formTable th{
  font-size:14px;
  border-bottom:1px solid #dfe6ec;
  border-right:1px solid #dfe6ec;
  margin:0;
  width: 100px;
  background:#F5F7FA;
  line-height: 150%;
}
</style>
